package com.jhy.new2025.BinaryTree;

import java.util.ArrayList;
import java.util.List;

/**
 * 前序遍历
 */
public class preorderTraversal {
    public List<Integer> preorderTraversal(TreeNode root) {
        List<Integer> res = new ArrayList<>();
        handle(root, res);
        return res;
    }

    public void handle(TreeNode root, List<Integer> res) {
        if (root == null) {
            return;
        }
        res.add(root.val);
        handle(root.left, res);
        handle(root.right, res);
    }

}
